package com.lanjiu.lib.imclient.dto;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description: 群成员
 * @author: Panwei
 * @date: 2019/11/14 17:09
 */
public class GroupMemberDto extends Dto {

    // 当前用户类型
    private String currentUserType;

    // 群成员ID
    private String groupMemberId;

    // 群成员用户ID
    private String groupMemberUserId;

    // 群成员名称
    private String groupNemberName;

    // 群成员昵称
    private String groupMemberAvatar;

    // 群成员身份(0:成员，1:群主)
    private int groupMemberType;

    // 群成员昵称
    private String groupMemberNick;

    // 群成员自定义备注
    private String groupMemberAlias;

    // 群成员用户类型
    private String userType;

    // 在线状态
    private String onlineStatus;

    // 所在群组
    private GroupDto group;

    public GroupMemberDto(String currentUserType) {
        this.currentUserType = currentUserType;
    }

    public String getCurrentUserType() {
        return currentUserType;
    }

    public void setCurrentUserType(String currentUserType) {
        this.currentUserType = currentUserType;
    }

    public String getGroupMemberId() {
        return groupMemberId;
    }

    public void setGroupMemberId(String groupMemberId) {
        this.groupMemberId = groupMemberId;
    }

    public String getGroupMemberUserId() {
        return groupMemberUserId;
    }

    public void setGroupMemberUserId(String groupMemberUserId) {
        this.groupMemberUserId = groupMemberUserId;
    }

    public String getGroupNemberName() {
        return groupNemberName;
    }

    public void setGroupNemberName(String groupNemberName) {
        this.groupNemberName = groupNemberName;
    }

    public String getGroupMemberAvatar() {
        return groupMemberAvatar;
    }

    public void setGroupMemberAvatar(String groupMemberAvatar) {
        this.groupMemberAvatar = groupMemberAvatar;
    }

    public int getGroupMemberType() {
        return groupMemberType;
    }

    public void setGroupMemberType(int groupMemberType) {
        this.groupMemberType = groupMemberType;
    }

    public String getGroupMemberNick() {
        return groupMemberNick;
    }

    public void setGroupMemberNick(String groupMemberNick) {
        this.groupMemberNick = groupMemberNick;
    }

    public String getGroupMemberAlias() {
        return groupMemberAlias;
    }

    public void setGroupMemberAlias(String groupMemberAlias) {
        this.groupMemberAlias = groupMemberAlias;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getOnlineStatus() {
        return onlineStatus;
    }

    public void setOnlineStatus(String onlineStatus) {
        this.onlineStatus = onlineStatus;
    }

    public GroupDto getGroup() {
        return group;
    }

    public void setGroup(GroupDto group) {
        this.group = group;
    }

    public GroupMemberDto(BusinessProtocolEntities.TouristsGroupMember groupMember) {
        this.currentUserType = IMSContacts.UserType.TOURISTS_USER;
        this.groupMemberId = groupMember.getGroupMemberId();
        this.groupMemberUserId = groupMember.getGroupMemberUserId();
        this.groupNemberName = groupMember.getGroupMemberName();
        this.groupMemberAvatar = groupMember.getGroupMemberAvatar();
        this.groupMemberType = groupMember.getGroupMemberType();
        this.groupMemberNick = groupMember.getGroupMemberNick();
        this.groupMemberAlias = groupMember.getGroupMemberAlias();
        this.userType = groupMember.getUserType();
        this.onlineStatus = groupMember.getOnlineStatus();
        BusinessProtocolEntities.TouristsGroup group = groupMember.getGroup();
        if (null != group)
            this.group = new GroupDto(group);
    }

    public GroupMemberDto(BusinessProtocolEntities.RegisteredGroupMember groupMember) {
        this.currentUserType = IMSContacts.UserType.REGISTERED_USER;
        this.groupMemberId = groupMember.getGroupMemberId();
        this.groupMemberUserId = groupMember.getGroupMemberUserId();
        this.groupNemberName = groupMember.getGroupMemberName();
        this.groupMemberAvatar = groupMember.getGroupMemberAvatar();
        this.groupMemberType = groupMember.getGroupMemberType();
        this.groupMemberNick = groupMember.getGroupMemberNick();
        this.groupMemberAlias = groupMember.getGroupMemberAlias();
        this.userType = groupMember.getUserType();
        this.onlineStatus = groupMember.getOnlineStatus();
        BusinessProtocolEntities.RegisteredGroup group = groupMember.getGroup();
        if (null != group)
            this.group = new GroupDto(group);
    }

    @Override
    public Object toProtobuf() {
        if (IMSContacts.UserType.REGISTERED_USER.equals(currentUserType)) {
            BusinessProtocolEntities.RegisteredGroupMember.Builder builder = BusinessProtocolEntities.RegisteredGroupMember.newBuilder();
            if (null != groupMemberId) builder.setGroupMemberId(groupMemberId);
            if (null != groupMemberUserId) builder.setGroupMemberUserId(groupMemberUserId);
            if (null != groupNemberName) builder.setGroupMemberName(groupNemberName);
            if (null != groupMemberAvatar) builder.setGroupMemberAvatar(groupMemberAvatar);
            builder.setGroupMemberType(groupMemberType);
            if (null != groupMemberNick) builder.setGroupMemberNick(groupMemberNick);
            if (null != groupMemberAlias) builder.setGroupMemberAlias(groupMemberAlias);
            if (null != userType) builder.setUserType(userType);
            if (null != onlineStatus) builder.setOnlineStatus(onlineStatus);
            if (null != group)
                builder.setGroup((BusinessProtocolEntities.RegisteredGroup) group.toProtobuf());
            return builder.build();
        } else {
            BusinessProtocolEntities.TouristsGroupMember.Builder builder = BusinessProtocolEntities.TouristsGroupMember.newBuilder();
            if (null != groupMemberId) builder.setGroupMemberId(groupMemberId);
            if (null != groupMemberUserId) builder.setGroupMemberUserId(groupMemberUserId);
            if (null != groupNemberName) builder.setGroupMemberName(groupNemberName);
            if (null != groupMemberAvatar) builder.setGroupMemberAvatar(groupMemberAvatar);
            builder.setGroupMemberType(groupMemberType);
            if (null != groupMemberNick) builder.setGroupMemberNick(groupMemberNick);
            if (null != groupMemberAlias) builder.setGroupMemberAlias(groupMemberAlias);
            if (null != userType) builder.setUserType(userType);
            if (null != onlineStatus) builder.setOnlineStatus(onlineStatus);
            if (null != group)
                builder.setGroup((BusinessProtocolEntities.TouristsGroup) group.toProtobuf());
            return builder.build();
        }
    }
}
